package data

import (
	"context"
	"paint-guess/internal/biz"
)

func (rp *paintGuessRepo) InsertRoom(ctx context.Context, roomId, password string) error {
	room := biz.Room{
		RoomId:   roomId,
		Password: password,
	}

	result := rp.data.db.Create(&room)
	return result.Error
}

func (rp *paintGuessRepo) GetRoomByRoomId(ctx context.Context, roomId string) (*biz.Room, error) {
	var room biz.Room
	result := rp.data.db.Where("room_id = ?", roomId).Find(&room)
	if result.Error != nil {
		return nil, result.Error
	}
	return &room, nil
}

func (rp *paintGuessRepo) DeleteRoomByRoomId(ctx context.Context, roomId string) (int64, error) {
	var room biz.Room
	result := rp.data.db.Where("room_id = ?", roomId).Delete(&room)
	if result.Error != nil {
		return 0, result.Error
	}
	return result.RowsAffected, nil
}
